
import 'package:flutter/cupertino.dart';
import 'package:flutter_deer/account/models/account_summary_entity.dart';
import 'package:flutter_deer/index/iview/game_unstart_iview.dart';
import 'package:flutter_deer/index/models/football_ratio_entity.dart';
import 'package:flutter_deer/index/models/user_betting_entity.dart';
import 'package:flutter_deer/mvp/base_page_presenter.dart';
import 'package:flutter_deer/net/base_entity.dart';
import 'package:flutter_deer/net/dio_utils.dart';
import 'package:flutter_deer/net/http_api.dart';


class GameUnstartPagePresenter extends BasePagePresenter<GameUnstartIMvpView> {

  @override
  void initState() {
  }

  Future<dynamic> getAccountSummary() async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      requestNetwork<BaseEntity<AccountSummaryEntity>>(Method.get,
          url: HttpApi.accountSummary,
          onSuccess: (data) {
            view.setAccountSummary(data!.data);
          },
          onError: (code, msg) {

          }
      );
    });
  }

  Future<dynamic> getUnstartGameGroupList() async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      asyncRequestNetwork<BaseEntity<List<FootballRatioGroupEntity>>>(Method.get,
          url: HttpApi.unstartGameGroupList,
          onSuccess: (data) {
            List<FootballRatioGroupEntity>? list = data!.data;
            view.setGameGroups(list);
          },
          onError: (code,msg) {

          }
      );
    });
  }

  Future<dynamic> getUnstartGameRatioList() async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      asyncRequestNetwork<BaseEntity<List<FootballGameUnstartEntity>>>(Method.get,
          url: HttpApi.unstartGameList,
          onSuccess: (data) {
            List<FootballGameUnstartEntity>? list = data!.data;
            view.setRatios(list);
          },
          onError: (code,msg) {

          }
      );
    });
  }

  Future<dynamic> computeResidueGiveScore() async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      asyncRequestNetwork<DoubleBaseEntity>(Method.get,
        url: HttpApi.residueGiveScore,
        onSuccess: (data) {
          view.setResidueGiveScore(data!.data);
        },
          onError: (code,msg) {
          }
      );
    });
  }

  Future<dynamic> saveBetting(String? ratioId,String? playWay,String? bettingType,String? useScoreType,double? score) async {
    UserBettingEntity userBettingEntity = new UserBettingEntity(isGroup: '0',ratioId: ratioId,playWay: playWay,bettingType: bettingType,useScoreType: useScoreType,score: score,groupId: '0',orderNo: '');
    return asyncRequestNetwork<StringBaseEntity>(Method.post,
        url: HttpApi.saveBetting,
        params: userBettingEntity.toJson(),
        onSuccess: (data) {
          view.setBettingResult(data!.data);
        },
        onError: (code,msg) {
        }
    );
  }

}